Repository navigation
Avoid per-row queries for evolution condition variables and natures - #1690
Open
santichausis wants to merge 2 commits into
Open
santichausis wants to merge 2 commits into
santichausis wants to merge 2 commits into
Conversation
FallenDeity
requested changes
Sep 30, 2026
get_condition_expression and get_allowed_natures ran a query per PokemonEvolution row. Milcery -> Alcremie has 63 rows, each with a condition_expression, so its evolution chain took 65 queries. Both tables are tiny (4 evolution variables, 25 natures), so load each once, lazily, on the serializer instance. A ListSerializer reuses its child instance for every row, so this is one query per list instead of one per row, without sharing state across requests.
santichausis
force-pushed
the
perf/evolution-detail-lookups
branch
from
September 30, 2026 11:53
003f0ff to
7f96c55
Compare
The cached lookups still ran the summary serializers once per evolution row. Serialize each table once alongside the query and reuse the results; serializing Alcremie's chain (63 rows) drops from ~52 ms to ~32 ms locally with identical output. Variables are kept as (symbol, data) pairs instead of a dict, since symbol isn't unique across version groups.
FallenDeity
approved these changes
Oct 25, 2026
Contributor
|
lgtm :) thanks, just remove the comments on top of the properties its evident in the code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PokemonEvolutionSerializer.get_condition_expressionandget_allowed_naturesrun one query perPokemonEvolutionrow. Milcery → Alcremie has 63 evolution rows, each with acondition_expression, so/evolution-chain/452/takes 65 queries (63 of them topokemon_v2_evolutionvariable).Fix
Both tables are tiny (4 evolution variables, 25 natures). Each is loaded and serialized once, lazily, through a
cached_propertyon the serializer instance, and each row picks its entries in Python, keeping the previous ordering. Variables are kept as(symbol, data)pairs rather than a dict, sincesymbolisn't unique across version groups.ListSerializerreuses a single child instance for every row, so this is one query per list of evolution details instead of one per row, and no state is shared across requests.Verification
condition_expressionandnature_bitmask), asserts the query count is the same, and checks the resolved variables and natures. This is the first API test coverage for these two fields. It usescachalot_disabled(), because inside the test transaction cachalot serves identical repeated queries from memory, which hides per-row queries. On master this test fails with 13 vs 5 queries.manage.py test pokemon_v2(64 tests), ruff, and ty (no new diagnostics) pass.